package com.train.order.core.handler.sentinel;

import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.esotericsoftware.minlog.Log;
import com.train.common.enums.impl.BizExceptionEnums;
import com.train.common.exception.GlobalException;
import com.train.common.resp.CommonResp;
import com.train.order.req.confirm.ConfirmOrderTicketReq;
import com.train.order.req.pay.PayOrderTicketReq;

/**
 * sentinel限流降级处理
 */
public class SentinelBlockHandler {

    /**
     * confirmOrder方法降级处理
     * @param dto
     * @param e
     */
//    public static void confirmOrderBlock(ConfirmOrderTicketDTO dto, BlockException e) {
//        Log.info("购票请求被限流: {}", dto.toString());
//        throw new GlobalException(BizExceptionEnums.EXP_CONFIRM_ORDER_BLOCK);
//    }

    /**
     * /confirm-order/confirm接口降级处理
     * @param req
     * @param e
     * @return
     */
    public static CommonResp confirmOrderBlock(ConfirmOrderTicketReq req, BlockException e) {
        Log.info("订单确认请求被限流: {}", req.toString());
        throw new GlobalException(BizExceptionEnums.EXP_CONFIRM_ORDER_BLOCK);
    }

    /**
     * /pay-order/pay接口降级处理
     * @param req
     * @param e
     * @return
     */
    public static CommonResp payOrderBlock(PayOrderTicketReq req, BlockException e) {
        Log.info("订单支付请求被限流: {}", req.toString());
        throw new GlobalException(BizExceptionEnums.EXP_PAY_ORDER_BLOCK);
    }
}
